VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsVertexTie"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'/******************************************************************/
'/*                                                                */
'/*                      TurboCAD for Windows                      */
'/*                   Copyright (c) 1993 - 2001                    */
'/*             International Microcomputer Software, Inc.         */
'/*                            (IMSI)                              */
'/*                      All rights reserved.                      */
'/*                                                                */
'/******************************************************************/

Option Explicit

Implements ITurboCADSmartTieServer

Public Type VertexTieData
    idVrtSbj As Long
    idVrtSbd As Long
End Type

Private idVTie As String

Private gxTSets As TieSets
Private gxTSet  As TieSet
Private gxTie   As Tie
Private gxDwg   As Drawing
Private tieData As VertexTieData
    
Private gxVrtsSbj As Vertices
Private gxVrtsSbd As Vertices

Private gxGrs   As Graphics
Private gxGrSbj As Graphic
Private gxGrSbd As Graphic

Private Function Clear()
    
    Set gxVrtsSbj = Nothing
    Set gxVrtsSbd = Nothing
    
    Set gxGrSbj = Nothing
    Set gxGrSbd = Nothing
    Set gxGrs = Nothing
    Set gxTie = Nothing
    Set gxTSet = Nothing
    Set gxTSets = Nothing
    Set gxDwg = Nothing

End Function


Private Function ITurboCADSmartTieServer_AddTie(ByVal pIDispDwg As Object, ByVal idSbj As Long, ByVal idSbd As Long, ByVal lType As Long) As Boolean
    
    Dim varData As Variant
    Set gxDwg = pIDispDwg
    
    Set gxTSets = gxDwg.TieSets
    Set gxTSet = gxTSets.TieSet(idSbj, idSbd)
    If (gxTSet.Count = 0) Then
        tieData.idVrtSbj = lType
        tieData.idVrtSbd = -1
        varData = tieData
        gxTSet.AddTie idVTie, 1, varData
    Else
        Set gxTie = gxTSet(0)
        varData = gxTie.Data
        tieData = varData(0)
        tieData.idVrtSbd = lType
        varData = tieData
        gxTie.Data = tieData
    End If
    
    
    Set gxTSet = gxTSets.TieSet(idSbd, idSbj)
    If (gxTSet.Count = 0) Then
        tieData.idVrtSbj = -1
        tieData.idVrtSbd = lType
        varData = tieData
        gxTSet.AddTie idVTie, 1, varData
    Else
        Set gxTie = gxTSet(0)
        varData = gxTie.Data
        tieData = varData(0)
        tieData.idVrtSbj = lType
        varData = tieData
        gxTie.Data = tieData
    End If
    
    UpdateTie gxTSet
    ITurboCADSmartTieServer_AddTie = True
    Clear

End Function

Private Function ITurboCADSmartTieServer_CopyTie(ByVal pIDispDwg As Object, ByVal idSbjSrc As Long, ByVal idSbdSrc As Long, ByVal idSbjTrg As Long, ByVal idSbdTrg As Long) As Boolean
    
    Set gxDwg = pIDispDwg
    Set gxGrs = gxDwg.Graphics
    Set gxGrSbj = gxGrs.GraphicFromID(idSbjTrg)
    Set gxGrSbd = gxGrs.GraphicFromID(idSbdTrg)
    
    Set gxTSets = gxDwg.TieSets
    Set gxTSet = gxTSets.TieSet(idSbjSrc, idSbdSrc)
    Set gxTie = gxTSet(0)
    tieData = gxTie.Data
    
    Set gxTSet = gxTSets.Add(idVTie, gxGrSbj, gxGrSbd, tieData.idVrtSbj, 0)
    
    Set gxTie = gxTSet(0)
    gxTie.Data = tieData
    
    Clear

    ITurboCADSmartTieServer_CopyTie = True
End Function

Private Function ITurboCADSmartTieServer_DeleteTie(ByVal pIDispDwg As Object, ByVal idSbj As Long, ByVal idSbd As Long, ByVal pIDsipGr As Object) As Boolean
    ITurboCADSmartTieServer_DeleteTie = True
End Function

Private Property Get ITurboCADSmartTieServer_Description() As String
    ITurboCADSmartTieServer_Description = "Vertex tie"
End Property

Private Function ITurboCADSmartTieServer_GetIDs(ByVal pIDispDwg As Object, ByVal idSbj As Long, ByVal idSbd As Long) As Variant
' It is not need to do something here because this method doesn't use Graphic's DataBase ID
End Function

Private Function ITurboCADSmartTieServer_GetTypesInfo(Names As Variant, Types As Variant) As Long
    ITurboCADSmartTieServer_GetTypesInfo = 0
End Function

Private Function ITurboCADSmartTieServer_Initialize(ByVal ThisTieMethod As Object) As Boolean
    Dim gxTMethod As TieMethod
    Set gxTMethod = ThisTieMethod
    idVTie = gxTMethod.Name
    ITurboCADSmartTieServer_Initialize = True
End Function

Private Function UpdateTie(ByRef gxTSet As TieSet)

    Dim gxVrtSbj As Vertex
    Dim gxVrtSbd As Vertex
    Dim varData As Variant
    Dim gxGrSbdNew As Graphic
    
    Dim gxDwg As Drawing
    Dim hDwg As Long
    Dim hGrSbd As Long
    Dim idSbd As Long
    
    Set gxTie = gxTSet(0)
    
    varData = gxTie.Data
    tieData = varData(0)
    
    If (tieData.idVrtSbd <> -1 And tieData.idVrtSbj <> -1) Then
        
            Set gxGrSbj = gxTSet.Subject
            Set gxGrSbd = gxTSet.Subordinate

            Set gxVrtsSbj = gxGrSbj.Vertices
            Set gxVrtsSbd = gxGrSbd.Vertices
            
            gxVrtsSbj.UseWorldCS = True
            gxVrtsSbd.UseWorldCS = True
            
            Set gxVrtSbj = gxVrtsSbj(tieData.idVrtSbj)
            Set gxVrtSbd = gxVrtsSbd(tieData.idVrtSbd)
            
            gxGrSbd.Deleted = True
            gxGrSbd.Draw
            gxGrSbd.Deleted = False
            
            gxVrtSbd.X = gxVrtSbj.X
            gxVrtSbd.Y = gxVrtSbj.Y
            gxVrtSbd.Z = gxVrtSbj.Z
            
            gxGrSbd.Draw
            
            Set gxVrtSbd = Nothing
            Set gxVrtSbj = Nothing
            Set gxGrSbj = Nothing
            Set gxGrSbd = Nothing
       
   
    End If
    
End Function

Private Sub ITurboCADSmartTieServer_SetIDs(ByVal pIDispDwg As Object, ByVal idSbj As Long, ByVal idSbd As Long, pvarIDs As Variant)
' It is not need to do something here because this method doesn't use Graphic's DataBase ID
End Sub

Private Function ITurboCADSmartTieServer_TieCanNODEED(ByVal pIDispDwg As Object, ByVal idSbj As Long, ByVal idSbd As Long) As Boolean
    ITurboCADSmartTieServer_TieCanNODEED = True
End Function

Private Function ITurboCADSmartTieServer_UpdateTie(ByVal pIDispDwg As Object, ByVal idSbj As Long, ByVal idSbd As Long) As Integer
    
    Set gxDwg = pIDispDwg
    
    Set gxTSets = gxDwg.TieSets
    
    Set gxTSet = gxTSets.TieSet(idSbj, idSbd)
    
    UpdateTie gxTSet

    ITurboCADSmartTieServer_UpdateTie = 0
    Clear

End Function
